#ifndef TEMPCTRLIB_H_
#define	TEMPCTRLIB_H_

#include <stdint.h>
#include "pid.h"

#ifdef	__cplusplus
extern "C" {
#endif

#define PidCal(x)			IndPid(x)

	typedef enum
	{
		TEMP_HEAT_INIT = 0,
		TEMP_HEAT_FULL = 1,
		TEMP_COOL,
		TEMP_HEAT,
		TEMP_AUTO,
		TEMP_BACKUP
	} temp_ctr_step_type;

	#define TEMP_DIR_DOWN  0
	#define TEMP_DIR_UP  1

	typedef enum
	{
		ADJ_LIMITE_MIN = 0,	
		ADJ_LIMITE_MAX = 1,	
	} TadjModeType;

	#define COOL_MODE_FORCE_DIS								0
	#define COOL_MODE_FORCE_EN								1
	#define COOL_MODE_AUTO_FIX								2
	#define COOL_MODE_AUTO_MIN								3
	#define COOL_MODE_AUTO_MAX								4
	
	typedef struct
	{
		uint8_t b_temp_man_on;								
		uint8_t b_temp_man_cool_req;						
		uint16_t temp_man_heat_out;							
		
		uint8_t cool_mode;									
		uint8_t b_heat_dis;									
		int16_t temp_pv;									
		int16_t temp_sv;									
		int16_t temp_cool_en;								
		int16_t temp_cool_dis;								
		int16_t temp_ctr_lmt_high;							
		int16_t temp_ctr_lmt_low;							
		int16_t cool_dly_time_sv;							
		float   f_temp_sv;									
		
		temp_ctr_step_type  temp_ctr_step;					
		int16_t temp_max;									
		int16_t temp_min;									
		int16_t cool_close_time_cnt;						
		uint8_t wave_cnt;									
		int16_t temp_heat_close;							
		int8_t b_cen_at_dly_end;							
		
		int8_t b_temp_dir;									
		int8_t b_temp_dir_old;								
		int8_t b_temp_dir_at_dly_end;						
		uint8_t temp_keep_cnt;								
		uint8_t temp_dir_keep_cnt;							
		uint8_t b_cool_req;									
		uint8_t b_cool_req_old;								
		uint8_t b_temp_cool_req;							
		uint8_t b_edge_cool_delay_end;						
		int16_t temp_for_dir;								
		int16_t temp_cool_dly_end;							
		int16_t temp_cool_end;								
		int16_t err_dis_to_dly_end;							
		int16_t temp_pv_old;								
		int16_t temp_sv_old;								
		int16_t cool_time_set;								
		int16_t cool_time_cnt_old;							
		int16_t cool_time_cnt;								
		int16_t cool_dly_time_sv_old;						
		int16_t cool_dly_time_cnt;							
		int32_t heat_out;									
		pid_type pid_temp;									
		uint32_t time_cnt;									
		uint32_t step_time_cnt;								
		temp_ctr_step_type  temp_ctr_step_old;				
	} temp_box_ctr_type;

	void temp_box_ctr(temp_box_ctr_type *TempCtrPar);		

#ifdef	__cplusplus
}
#endif

#endif	

